#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "util.h"
#include "types.h"
#include "z80mem.h"

z80Mem::z80Mem()
{
    buffer.resize(RAMSIZE);
}

z80Mem::~z80Mem()
{
    buffer.clear();
    buffer.~vector();
}

void z80Mem::peek(int size)
{
    sethex(std::cout);

    for(int i = 0; i < size; i++)
    {
      std::cout << buffer[i] << std::endl;
    }          

    reset(std::cout);
}

void z80Mem::clear()
{ 
    buffer.assign(RAMSIZE, 0);
}

void z80Mem::load(std::string fname)
{
    clear();
    
    std::ifstream file(fname.c_str(), std::ifstream::in | std::ifstream::binary);

    std::cout << "RAM: " << fname << " [" << length(file) << "]" << std::endl;

    file.read((char*)&this->buffer[0], sizeof(byte)*RAMSIZE);

    file.close();
}
